package comAPIdlw.tool;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.Security;

/**
 * @Author: dlw
 * @Hobby:
 * @QQ : 2378116345
 * @Date: 2021/12/23 9:23
 * @desc:该类用于生成各种类型的hash算法
 */
//该方法用于给特定数据data进行sha256 hash计算，返回哈希结果
public class Hash {

    public  static byte[] SHA256(byte[] data){
        //md ：message  digest  信息摘要 消息摘要
        try {
            MessageDigest digest=MessageDigest.getInstance("SHA-256");
            digest.update(data);
           return digest.digest();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }

    public  static byte[] RipeMD160(byte[] data){
             Security.addProvider(new BouncyCastleProvider());

        try {
            MessageDigest digest = MessageDigest.getInstance("RipeMD160");
            digest.update(data);
            return digest.digest();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }


        return null;
    }

}








